package com.yxw.jdbc;

import com.mysql.cj.jdbc.Driver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Properties;

public class MyJdbc {
/*><*/    public static void main(String[] args) throws Exception {


        Class<?> clazz = Class.forName("com.mysql.cj.jdbc.Driver");
//        Driver driver1 = (Driver) clazz.getDeclaredConstructor().newInstance();
//        DriverManager.registerDriver(driver1);
//        driver1.connect()

        Properties properties = new Properties();
        properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties"));
        var url = "jdbc:mysql://localhost:3306/student?serverTimezone=UTC";
        var username = "root";
        var password = "123456";

        Driver driver = new Driver();
//        Connection connect = driver.connect(url, properties);
//        System.out.println(connect);

        //serverTimezone=Asia/Shanghai
        var connection = DriverManager.getConnection(url, properties);

        var sql = "update user set age = ?, address = ? where id = ?";
        var sql2 = "delete from user where id = ? ";
//        Statement statement = connection.createStatement();
//        statement.executeUpdate(sql);
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1,29);
        preparedStatement.setString(2,"湖南");
        preparedStatement.setInt(3,33);
        var i = preparedStatement.executeUpdate();
        System.out.println(i);

//        PreparedStatement preparedStatement1 = connection.prepareStatement(sql2);
//        preparedStatement1.setInt(1,5);
//        System.out.println(preparedStatement1.executeUpdate());

//        if (preparedStatement1 != null) {
//            preparedStatement1.close();
//        }
        if (preparedStatement != null) {
            preparedStatement.close();
        }

    }
}
